package com.google.code.jerseyclients;

/*
 * Olivier Lamy
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.util.HashMap;
import java.util.Map;

import com.google.code.jerseyclients.model.ProxyInformation;
import com.sun.jersey.api.client.config.DefaultClientConfig;

/**
 * @author <a href="mailto:olamy@apache.org">Olivier Lamy</a>
 * @since 1.0
 * @version $Id: DefaultJerseyHttpClientConfig.java 8 2010-11-04 17:33:00Z oliver.lamy@gmail.com $
 */
public class DefaultJerseyHttpClientConfig
    extends DefaultClientConfig
    implements JerseyHttpClientConfig
{

    public static final String DEFAULT_APPLICATION_CODE_HEADER = "Application-Code";

    private int connectionTimeOut;

    private int maxConnections;

    private int maxConnectionsPerHost;

    private int readTimeOut;

    private boolean connectionStaleCheckingEnabled = false;

    private int connectionPoolTimeOut;

    private String applicationCode;

    private String applicationCodeHeader;
    
    private Map<String, String> optionnalHeaders;
    
    private ProxyInformation proxyInformation;
    
    private boolean reuseConnection = true;
    
    private int idleConnectionTimeout = 60000;

    public int getConnectionTimeOut()
    {
        return connectionTimeOut;
    }

    public JerseyHttpClientConfig setConnectionTimeOut( int connectionTimeOut )
    {
        this.connectionTimeOut = connectionTimeOut;
        return this;
        
    }

    public int getMaxConnections()
    {
        return maxConnections;
    }

    public JerseyHttpClientConfig setMaxConnections( int maxConnections )
    {
        this.maxConnections = maxConnections;
        return this;
    }

    public int getMaxConnectionsPerHost()
    {
        return maxConnectionsPerHost;
    }

    public JerseyHttpClientConfig setMaxConnectionsPerHost( int maxConnectionsPerHost )
    {
        this.maxConnectionsPerHost = maxConnectionsPerHost;
        return this;
    }

    public int getReadTimeOut()
    {
        return readTimeOut;
    }

    public JerseyHttpClientConfig setReadTimeOut( int readTimeOut )
    {
        this.readTimeOut = readTimeOut;
        return this;
    }

    public boolean isConnectionStaleCheckingEnabled()
    {
        return connectionStaleCheckingEnabled;
    }

    public JerseyHttpClientConfig setConnectionStaleCheckingEnabled( boolean connectionStaleCheckingEnabled )
    {
        this.connectionStaleCheckingEnabled = connectionStaleCheckingEnabled;
        return this;
    }

    public int getConnectionPoolTimeOut()
    {
        return connectionPoolTimeOut;
    }

    public JerseyHttpClientConfig setConnectionPoolTimeOut( int connectionPoolTimeOut )
    {
        this.connectionPoolTimeOut = connectionPoolTimeOut;
        return this;
    }

    public String getApplicationCode()
    {
        return applicationCode;
    }

    public JerseyHttpClientConfig setApplicationCode( String applicationCode )
    {
        this.applicationCode = applicationCode;
        return this;
    }

    public String getApplicationCodeHeader()
    {
        return applicationCodeHeader == null ? DEFAULT_APPLICATION_CODE_HEADER : applicationCodeHeader;
    }

    public JerseyHttpClientConfig setApplicationCodeHeader( String applicationCodeHeader )
    {
        this.applicationCodeHeader = applicationCodeHeader;
        return this;
    }

    public Map<String, String> getOptionnalHeaders()
    {
        if (optionnalHeaders == null)
        {
            optionnalHeaders = new HashMap<String, String>();
        }
        return optionnalHeaders;
    }

    public JerseyHttpClientConfig setOptionnalHeaders( Map<String, String> optionnalHeaders )
    {
        this.optionnalHeaders = optionnalHeaders;
        return this;
    }

    public ProxyInformation getProxyInformation()
    {
        return proxyInformation;
    }

    public JerseyHttpClientConfig setProxyInformation( ProxyInformation proxyInformation )
    {
        this.proxyInformation = proxyInformation;
        return this;
    }

    public boolean isReuseConnection()
    {
        return reuseConnection;
    }

    public JerseyHttpClientConfig setReuseConnection( boolean reuseConnection )
    {
        this.reuseConnection = reuseConnection;
        return this;
    }

    public int getIdleConnectionTimeout()
    {
        return idleConnectionTimeout;
    }

    public JerseyHttpClientConfig setIdleConnectionTimeout( int idleConnectionTimeout )
    {
        this.idleConnectionTimeout = idleConnectionTimeout;
        return this;
    }
}